/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InterfaceOpImovel.java
 *
 * Created on 06/07/2010, 22:42:54
 */

package imobiliaria.gui;

import imobiliaria.auxiliar.TipoContratual;
import imobiliaria.auxiliar.TipoImovel;
import imobiliaria.controladores.ControladorImovel;
import imobiliaria.entidades.Aluguel;
import imobiliaria.entidades.Imovel;
import imobiliaria.entidades.Sistema;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author jeanderson
 */
public class InterfaceOpImovel extends javax.swing.JFrame {
    private Sistema sis;
    /** Creates new form InterfaceOpImovel */
    public InterfaceOpImovel() {
        sis = new Sistema();
	try {
	    sis.atualizaDados();
	} catch (Exception e) {
	    System.out.println("Erro: " + e.getMessage());
	}
        initComponents();
        setLocationRelativeTo(null);
        atualizaImoveis();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        JLI_ImoveisTotal = new javax.swing.JList();
        JB_Voltar = new javax.swing.JButton();
        jB_CadastroImovel = new javax.swing.JButton();
        jB_ExcluirCadastro = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jT_Endereco = new javax.swing.JTextField();
        jT_Descricao = new javax.swing.JTextField();
        jL_Sit = new javax.swing.JLabel();
        jL_EstadoImovel = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        Alguel = new javax.swing.JRadioButton();
        Venda = new javax.swing.JRadioButton();
        jPanel6 = new javax.swing.JPanel();
        jR_AP = new javax.swing.JRadioButton();
        jR_Terreno = new javax.swing.JRadioButton();
        jR_casa = new javax.swing.JRadioButton();
        jT_PRECO = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        jT_Comp = new javax.swing.JTextField();
        jC_Imoveis = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Opções Imóveis");
        setResizable(false);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(" Listagem Total "));

        JLI_ImoveisTotal.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(JLI_ImoveisTotal);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 578, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                .addContainerGap())
        );

        JB_Voltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/backIcon.png"))); // NOI18N
        JB_Voltar.setText("Voltar");
        JB_Voltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_VoltarActionPerformed(evt);
            }
        });

        jB_CadastroImovel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/addIcon.png"))); // NOI18N
        jB_CadastroImovel.setText("Cadastrar Imóvel");
        jB_CadastroImovel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_CadastroImovelActionPerformed(evt);
            }
        });

        jB_ExcluirCadastro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/exitIcon.png"))); // NOI18N
        jB_ExcluirCadastro.setText("Excluir Imóvel");
        jB_ExcluirCadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_ExcluirCadastroActionPerformed(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/iMobLogo.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(64, 64, 64)
                        .addComponent(jLabel1)
                        .addGap(129, 129, 129)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JB_Voltar, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                            .addComponent(jB_ExcluirCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jB_CadastroImovel))
                        .addGap(18, 18, 18)))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {JB_Voltar, jB_CadastroImovel, jB_ExcluirCadastro});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jB_CadastroImovel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jB_ExcluirCadastro)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JB_Voltar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(93, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addContainerGap())))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {JB_Voltar, jB_CadastroImovel, jB_ExcluirCadastro});

        jTabbedPane1.addTab("Listagem de Imóveis", jPanel1);

        jPanel3.setLayout(null);

        jLabel2.setText("Selecione o Imóvel:");
        jPanel3.add(jLabel2);
        jLabel2.setBounds(10, 20, 140, 15);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Dados ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        jPanel4.setPreferredSize(new java.awt.Dimension(605, 104));

        jLabel3.setText("Descrição:");

        jLabel4.setText("Endereço:");

        jT_Descricao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jT_DescricaoActionPerformed(evt);
            }
        });

        jL_Sit.setText("Situação do Imóvel:");

        jL_EstadoImovel.setForeground(new java.awt.Color(255, 0, 0));
        jL_EstadoImovel.setText(" ");

        jLabel8.setText("Preço:");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Contrato ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        buttonGroup1.add(Alguel);
        Alguel.setText("Aluguel");

        buttonGroup1.add(Venda);
        Venda.setText("Venda");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Alguel)
                    .addComponent(Venda))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Alguel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Venda)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Tipo do Imóvel ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        buttonGroup2.add(jR_AP);
        jR_AP.setText("Apartamento");

        buttonGroup2.add(jR_Terreno);
        jR_Terreno.setText("Terreno");

        buttonGroup2.add(jR_casa);
        jR_casa.setText("Casa");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jR_AP)
                    .addComponent(jR_Terreno)
                    .addComponent(jR_casa))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jR_AP)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jR_Terreno)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jR_casa)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Dimensões ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jT_Comp.setEditable(false);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jT_Comp, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jT_Comp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel8))
                        .addGap(39, 39, 39)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jT_Endereco, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
                            .addComponent(jT_Descricao, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
                            .addComponent(jT_PRECO, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jL_Sit)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jL_EstadoImovel, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE))
                            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jT_Descricao, jT_Endereco});

        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jT_Descricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jT_Endereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jT_PRECO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jL_Sit)
                            .addComponent(jL_EstadoImovel))))
                .addGap(29, 29, 29))
        );

        jPanel3.add(jPanel4);
        jPanel4.setBounds(0, 40, 650, 330);

        jC_Imoveis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jC_ImoveisActionPerformed(evt);
            }
        });
        jPanel3.add(jC_Imoveis);
        jC_Imoveis.setBounds(160, 10, 460, 25);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imobiliaria/images/saveIcon.png"))); // NOI18N
        jButton1.setText("Salvar Registro");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton1);
        jButton1.setBounds(230, 420, 170, 40);

        jTabbedPane1.addTab("Informações", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 660, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 548, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JB_VoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_VoltarActionPerformed
        dispose();
}//GEN-LAST:event_JB_VoltarActionPerformed

    private void jB_CadastroImovelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_CadastroImovelActionPerformed
        // TODO add your handling code here:
        new CadastrarImovel().setVisible(true);
        dispose();
    }//GEN-LAST:event_jB_CadastroImovelActionPerformed

    private void jB_ExcluirCadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_ExcluirCadastroActionPerformed
        // TODO add your handling code here:

        Imovel imovelExcluir = (Imovel) JLI_ImoveisTotal.getSelectedValue();
        JOptionPane.showMessageDialog(null, "O seguinte imovel está sendo excluido:\n\n"
                + "Descrição: " + imovelExcluir.getNome()
                + "\nEndereço:" + imovelExcluir.getEndereco()
                + "\nRegistro:" + imovelExcluir.getRegistroImovel() + "\n\n",
                    "Confirmar Exclusão", JOptionPane.YES_OPTION);

        String registro = imovelExcluir.getRegistroImovel() + "";
        try {
            ControladorImovel.getInstance().removeImovel(registro);
        } catch (Exception ex) {
            Logger.getLogger(InterfaceOpImovel.class.getName()).log(Level.SEVERE, null, ex);
        }
        sis.salvarDados();
        atualizaImoveis();

        
    }//GEN-LAST:event_jB_ExcluirCadastroActionPerformed

    private void jC_ImoveisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jC_ImoveisActionPerformed
        // TODO add your handling code here:
        Imovel imvSelected = (Imovel) jC_Imoveis.getSelectedItem();
        jT_Descricao.setText(imvSelected.getNome());
        jT_Endereco.setText(imvSelected.getEndereco());
        jL_EstadoImovel.setText(imvSelected.getEstadoDoImovel().toString());
        jT_PRECO.setText(imvSelected.getValor() + "");

        if (imvSelected.getTipoContratual().equals(TipoContratual.ALUGUEL)) {
            Alguel.setSelected(true);
            Venda.setSelected(false);
        } else {
            Venda.setSelected(true);
            Alguel.setSelected(false);
        }

        if (imvSelected.getTipoDoImovel().equals(TipoImovel.APARTAMENTO)){
            jR_AP.setSelected(true);
        } if (imvSelected.getTipoDoImovel().equals(TipoImovel.CASA)) {
            jR_casa.setSelected(true);
        } else {
            jR_Terreno.setSelected(true);
        }
        jT_Comp.setText(imvSelected.getArea() + "");
   
    }//GEN-LAST:event_jC_ImoveisActionPerformed

    private void jT_DescricaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jT_DescricaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jT_DescricaoActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:

        if (jC_Imoveis.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(null, "Nenhum Imovel Selecionado",
                    "Modificar", JOptionPane.ERROR_MESSAGE);
            return;
        }

        try {
            TipoImovel tipo = null;
            TipoContratual tipoCont = null;
            if (jR_AP.isSelected()){
                tipo = TipoImovel.APARTAMENTO;
            } else if (jR_casa.isSelected()) {
                tipo = TipoImovel.CASA;
            } else if (jR_Terreno.isSelected()) {
                tipo = TipoImovel.TERRENO;
            }

            if (Alguel.isSelected()){
                tipoCont = TipoContratual.ALUGUEL;
            } else if (Venda.isSelected()) {
                tipoCont = TipoContratual.VENDA;
            }

        Imovel imovel = ((Imovel) jC_Imoveis.getSelectedItem());
        Double valor = Double.parseDouble(jT_PRECO.getText());

        

        ControladorImovel.getInstance().modificaImovel(imovel.getRegistroImovel() + "",
                jT_Descricao.getText(), jT_Endereco.getText(), valor, imovel.getArea()
                , tipo, tipoCont);

        JOptionPane.showMessageDialog(null, "Imovel Modificado com sucesso",
                    "Modificar", JOptionPane.INFORMATION_MESSAGE);


        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro ao Modificar Imovel",
                    "Modificar", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private Imovel[] mostraImoveis(){

        Imovel[] imoveis = ControladorImovel.getInstance().listaImoveisGUI();
        
        return imoveis;
    }

    public void atualizaImoveis(){
        jC_Imoveis.removeAllItems();
        for (Imovel imv : mostraImoveis())
            jC_Imoveis.addItem(imv);

        JLI_ImoveisTotal.setModel(new javax.swing.AbstractListModel() {
            final Imovel[] strings = mostraImoveis();
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });

    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new InterfaceOpImovel().setVisible(true);
                
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton Alguel;
    private javax.swing.JButton JB_Voltar;
    private javax.swing.JList JLI_ImoveisTotal;
    private javax.swing.JRadioButton Venda;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton jB_CadastroImovel;
    private javax.swing.JButton jB_ExcluirCadastro;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jC_Imoveis;
    private javax.swing.JLabel jL_EstadoImovel;
    private javax.swing.JLabel jL_Sit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JRadioButton jR_AP;
    private javax.swing.JRadioButton jR_Terreno;
    private javax.swing.JRadioButton jR_casa;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jT_Comp;
    private javax.swing.JTextField jT_Descricao;
    private javax.swing.JTextField jT_Endereco;
    private javax.swing.JTextField jT_PRECO;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables

}
